#!/usr/bin/node

const log = console.log,
        arg = process.argv[2];
log('argv[0]',process.argv[0])
log('argv[1]',process.argv[1])
if(process.argv[2]){
  log('argv[2]',process.argv[2])
}

if(typeof(arg) === 'undefined' ||
        arg === '--help' ||
        arg === '-h') {
            help()
        } else {
            calc()
        }

function help() {
    const msg = '' 
          + 'usage: cmd-name [OPTION] [expression]\n'
              + 'evaluate the expression.\n'
                  + '\n'
                      + 'Mandatory arguments to long options are mandatory for short options too.\n'
                          + '  -h, --help output help information and exit\n';

      log(msg);

}

function calc() {
  try{
    log(`${arg} = ${eval(arg)}`)
  }catch(e) {
    console.error(`${arg} is not a correct expression!`)
  }
}
